package com.community.manage.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.community.common.entity.vo.UserLoginVo;
import com.community.common.utils.JwtUtils;
import org.springframework.data.redis.core.RedisTemplate;

import javax.servlet.http.HttpServletRequest;

/**
 * 信息处理类
 */
public class ImformtionImpl {

    /**
     * 查找当前登录人
     * @param redisTemplate
     * @param request
     * @return
     */
    public static UserLoginVo findUserLogin(RedisTemplate<String,Object> redisTemplate, HttpServletRequest request){
        //获取token
        String token = request.getHeader(JwtUtils.TOKEN);
        // 解析token
        String userKey = JwtUtils.getUserKey(token);
        //获取数据
        String s = String.valueOf(redisTemplate.opsForValue().get(JwtUtils.LOGIN_TOKEN_KEY + userKey));
        // 反序列化
        UserLoginVo userLoginVo = JSONObject.parseObject(s, UserLoginVo.class);

        return userLoginVo;
    }
}
